package com.jilujia.domain.question.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.jilujia.domain.question.Answer;
import com.jilujia.framework.domain.JpaBusinessRepository;

@Repository
@Transactional(readOnly = true)
public interface AnswerRepository extends JpaBusinessRepository<Long, Answer> {

	@Query("select a from Answer a where a.question.id = :questionId")
	Page<Answer> findAnswersByQuestionId(@Param("questionId") Long questionId, Pageable pageable);

	@Query("select sum(a.voteCount) as avCount from Answer a where a.question.id = :questionId")
	Long sumAnswerVoteByQuestionId(@Param("questionId") Long questionId);
}
